package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.dto.DishDto;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:YZN
 * @date:2022/12/30
 * @description:
 */
@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 添加菜品
     * @param dishDto
     * @return
     */
    @PostMapping
    public R add(@RequestBody DishDto dishDto){
        return dishService.addDish(dishDto);
    }

    /**
     * 分页条件查询
     */
    @GetMapping("/page")
    public R page(@RequestParam("page") Integer page,@RequestParam("pageSize") Integer pageSize,@RequestParam(value = "name",required = false) String name){
        return dishService.findPage(page,pageSize,name);
    }

    /**
     * 根据菜品ID查询菜品信息
     */
    @GetMapping("/{id}")
    public R findById(@PathVariable("id") Long id){
        return dishService.findById(id);
    }

    /**
     * 菜品修改
     */
    @PutMapping
    public R modify(@RequestBody DishDto dishDto){
        return dishService.modify(dishDto);
    }

    /**
     * 菜品删除和批量删除
     */
    @DeleteMapping
    public R delete(@RequestParam("ids") Long[] ids){
        return dishService.delete(ids);
    }

    /**
     * 菜品的停售和批量停售
     */
    @PostMapping("/status/{type}")
    public R status(@PathVariable("type") Integer type,@RequestParam("ids") Long[] ids){
        return  dishService.status(type,ids);
    }

    /**
     * 根据ID查询菜品信息
     */
    @GetMapping("/list")
    public R list(@RequestParam(value = "categoryId")Long categoryId){
        return dishService.list(categoryId);
    }
}
